#ifndef FTKWINDOW_H
#define FTKWINDOW_H

#include <QMainWindow>
#include "widgettree.h"
#include "ftk_xul.h"

class FtkWindow : public QMainWindow
{
    friend class FtkXul;

    Q_OBJECT
public:
    explicit FtkWindow(WidgetTree *tree, QDomElement &element, QTreeWidgetItem *item, QWidget *parent = 0);
    int getUnusedId(void);
    bool setMainWidget(QWidget *widget);
    bool widgetSizeRelatively;
    bool widgetsRemoving;
    QWidget *mainWidget;

protected:
    void dragEnterEvent(QDragEnterEvent *event);
    void dragLeaveEvent(QDragLeaveEvent *event);
    void dragMoveEvent(QDragMoveEvent *event);
    void dropEvent(QDropEvent *event);
    void mousePressEvent(QMouseEvent *event);
    void mouseMoveEvent(QMouseEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);

private:
    WidgetTree *tree;
    QTreeWidgetItem *item;
    QDomElement element;
    QHash<QTreeWidgetItem *, QWidget *> widgetForItem;
    QHash<QWidget *, QDomElement> elementForWidget;
    int maxId;
    QList<QWidget *> selectWidgetList;
    QRubberBand *rubberBand;
    QPoint origin;
    bool widgetsDraging;
    QPoint dragPosition;
    void selectWidgets(const QObjectList& list, const QRect &rect);
    void clearSelectWidgets(void);
    void appendSelectWidget(QWidget *widget);
    void updateWidgetPos(QWidget *widget);
    void recalcRubberBand();
    void moveWidget(QWidget *widget, QPoint &newPos);
    void pasteWidgets(QList<QWidget *> &widetList);
    QList<QWidget *> clipBoard;
    QMenu *contextMenu;
    void createContextMenu();

signals:

private slots:
    void topAlign();
    void bottomAlign();
    void leftAlign();
    void rightAlign();
    void vCenterAlign();
    void hCenterAlign();
    void itemSelectChanged(QTreeWidgetItem *item);
    void removeSelectWidgets();
    void copySelectWidgets();
    void dupSelectWidgets();
    void pasteWidgets();
    void contextMenuSlot(QPoint pos);

public slots:
    void createTab(WidgetTree *tree,
                   QDomElement &element,
                   QTreeWidgetItem *item,
                   QWidget *parent=0);
    void createButton(WidgetTree *tree,
                      QDomElement &element,
                      QTreeWidgetItem *item,
                      QWidget *parent=0);
};

extern FtkWindow *curDesignWindow;

#endif // FTKWINDOW_H
